var currentUser;
var userType;
var id;
var bhaveBaseMoney = false;
var bhaveDealMoney = false;
var apis = "http://192.168.233.173:9200";
//屏幕高度
$(function () {
    $(".usercotent").css("min-height", $(window).height() - 180 + "px");
    //获取个人信息开始
})
function getSearchData() {
    var keyword = $.trim($("#search_keyvalue").val());

    if (keyword == "" || !keyword ) {
        var data = null;
    } else {
        var data= keyword;
    }

    return data;
}
var loginUserType;  //订单列表处用
function initSideAccMenu(parent, child) {
    var url="apis/user/getcurrent";
    var datajson={};
    $.ajax({
        url: url,
        type: 'get',
        // data: JSON.stringify(datajson),
        dataType: 'json',
        async: false,
        contentType : 'application/json',
        success: function (res) {
            // console.log(res);
            if (res.httpCode != 200) {
                window.top.location.href = "login.html";
            }
            else if (res.httpCode == 200) {
                loginUserType = res.data.usertype;
                $("#binddnyaccount").val(res.data.binddnyaccount);
                $("#binddnypsw").val(res.data.binddnypsw);
                var headerHtml='<div class="top">' +
                    '<div class="topbar">' +
                    '<div class="topbarl floatl text1">' +
                    '<span class="username" style="color: #E4393C">'+
                    res.data.userName+
                    '</span>' +
                    '&nbsp;&nbsp;&nbsp;欢迎来到微信小程序管理平台&nbsp;&nbsp;&nbsp;' +
                    '</div>' +
                    '<div class="topbarr floatr" style="width: 350px;text-align: right">' +
                    '<a href="javascript:;" id="sign">退出</a>' +
                    '</div>' +
                    '</div>' +
                    '<div class="clear"></div>' +
                    '</div>';
                $("#header").html(headerHtml);


                //退出登录
                $("#sign").click(function () {
                    var url="apis/user/logout";
                    var datajson={};
                    $.ajax({
                        url: url,
                        type: 'post',
                        data: JSON.stringify(datajson),
                        dataType: 'json',
                        contentType : 'application/json',
                        success: function (data, status, xhr) {
                            //console.log(data);
                            if (data.httpCode == 200) {
                                alert("退出登录成功");
                                window.location.href="login.html";
                            }
                        }

                    })
                })
                //退出登录结束
                userType = res.data.usertype;
                //console.log(res.data.menus);

                var menuLeft = $("#center-left");
                if ($(menuLeft).length > 0) {
                    $(menuLeft).empty();
                    var sHtmlMenu;
                    sHtmlMenu = "";
                    sHtmlMenu += "<div class=\"usercotentl\">";
                    sHtmlMenu += "<aside class=\"main-sidebar\">";
                    sHtmlMenu += "<section class=\"sidebar\">";
                    sHtmlMenu += "<ul class=\"sidebar-menu\">";
                    sHtmlMenu += "<li class=\"header-admin\">用户中心</li>";
                    var result = [];
                    var data = res.data.menus;
                    for (var i = 0; i < data.length; i++) {
                        sHtmlMenu += "<li class=\"treeview active\" menutitle=\"" + data[i].menuName + "\">";

                        sHtmlMenu += "<a href=\"javascript:;\">";
                        sHtmlMenu += "<i class=\"fa " + data[i].iconcls + "\"></i> <span>" + data[i].menuName + "</span>";
                        sHtmlMenu += "<i class=\"fa icon-angle-left pull-right\"></i>";
                        sHtmlMenu += "</a>";
                        sHtmlMenu += "<ul class=\"treeview-menu\">";
                        for (var j = 0; j < data[i].menuBeans.length; j++) {
                            sHtmlMenu += "<li><a menutitle=\"" + data[i].menuBeans[j].menuName + "\" href=\"" + data[i].menuBeans[j].request + "\"><i class=\"fa icon-circle-blank\"></i>  " + data[i].menuBeans[j].menuName + "</a></li>";

                        }
                        sHtmlMenu += "</ul>";

                        sHtmlMenu += "</li>";
                    }
                    // for (var i = 0; i < res.data.menus.length; i++) {
                    //     if(res.data.menus[i].parentId==0){
                    //         result.push(res.data.menus[i]);
                    //     }
                    //
                    // }
                    //console.log(result);
                    // for (var j = 0; j < result.length; j++) {
                    //     sHtmlMenu += "<li class=\"treeview active\" menutitle=\"" + result[j].menuName + "\">";
                    //
                    //     sHtmlMenu += "<a href=\"javascript:;\">";
                    //     sHtmlMenu += "<i class=\"fa " + result[j].iconcls + "\"></i> <span>" + result[j].menuName + "</span>";
                    //     sHtmlMenu += "<i class=\"fa icon-angle-left pull-right\"></i>";
                    //     sHtmlMenu += "</a>";
                    //     sHtmlMenu += "<ul class=\"treeview-menu\">";
                    //     for (var i = 0; i < res.data.menus.length; i++) {
                    //
                    //         if (result[j].id==res.data.menus[i].parentId){
                    //
                    //             sHtmlMenu += "<li><a menutitle=\"" + res.data.menus[i].menuName + "\" href=\"" + res.data.menus[i].request + "\"><i class=\"fa icon-circle-blank\"></i>  " + res.data.menus[i].menuName + "</a></li>";
                    //         }
                    //
                    //
                    //     }
                    //     sHtmlMenu += "</ul>";
                    //
                    //     sHtmlMenu += "</li>";
                    //
                    // }
                    sHtmlMenu += "</ul>";
                    sHtmlMenu += "</section>";
                    sHtmlMenu += "</aside>";
                    sHtmlMenu += "</div>";
                    $(menuLeft).append(sHtmlMenu);
                }
            }
            else {
                alert(res.msg);
            }
        }
    });

    var treeview = $(".treeview");
    //console.log($(".treeview").length);
    for (var i = 0; i < treeview.length; i++) {
        if ($(treeview[i]).attr("menutitle") == parent) {
            $(treeview[i]).addClass("active");

            var treeitem = $(treeview[i]).children('.treeview-menu').children("li").children('a');
            for (var j = 0; j < treeitem.length; j++) {
                if ($(treeitem[j]).attr("menutitle") == child) {
                    $(treeitem[j]).addClass("slted");
                }
            }
            break;
        }
    }

}

